<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 5. Image toolkit</a>
</td><td width="60%">
<p align="center">
=====================================<br />
5.7 Getting the average color of a part of the image<br />
=====================================<br />
</p></td><td width="20%">
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
This method uses <a href="http://en.wikipedia.org/wiki/Mipmap">mipmaps</a> to get the average color of an arbitrary rectangular region of the image.<br />
It can be used to draw a scaled-down version of the image. It's used by libtcod's blitting functions.<br />
<p class="code"><pre>
C++ : TCODColor TCODImage::getMipmapPixel(float x0,float y0, float x1, float y1)
C   : TCOD_color_t TCOD_image_get_mipmap_pixel(TCOD_image_t image,float x0,float y0, float x1, float y1)
Py  : image_get_mipmap_pixel(image,x0,y0, x1, y1)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>image</td><td>In the C version, the image handler, obtained with the <a href="image_load.html">load</a> function.</td></tr>
<tr><td>x0,y0</td><td>Coordinates in pixels of the upper-left corner of the region.<br />0.0 &lt;= x0 &lt; x1<br />0.0 &lt;= y0 &lt; y1<br /></td></tr>
<tr><td>x1,y1</td><td>Coordinates in pixels of the lower-right corner of the region.<br />x0 &lt; x1 &lt; width<br />y0 &lt; y1 &lt; height<br /></td></tr>
</table>
Example :<br />
Get the average color of a 5x5 "superpixel" in the center of the image.<br />
<p class="code"><pre>
C++ : TCODImage *pix = new TCODImage(80,50);
      TCODColor col=pix->getMipMapPixel(37.5f, 22.5f, 42.5f, 28.5f);
C   : TCOD_image_t pix = TCOD_image_new(80,50);
      TCOD_color_t col=TCOD_image_get_mipmap_pixel(pix,37.5f, 22.5f, 42.5f, 28.5f);
Py  : pix = libtcod.image_new(80,50)
      col=libtcod.image_get_mipmap_pixel(pix,37.5, 22.5, 42.5, 28.5)
</pre></p>
